package com.ruoyi.test.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.test.domain.Cinema;
import com.ruoyi.test.service.CinemaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cinema")
public class CinemaController extends BaseController {

    @Autowired
    private CinemaService cinemaService;

    // 测试接口
    @GetMapping("/apiTest/hello")
    public String HelloApi() {
        return "hello";
    }

    // 查询所有影院
    @GetMapping("/queryAllCinema")
    public AjaxResult queryAllCinema() {
        List<Cinema> cinema = cinemaService.queryAllCinema();
        return AjaxResult.success(cinema);
    }

    /**
     * mapper对应xml中sql的对应关系说明:
     * cinema表示xml里吗的parameterType => 表示传入的参数类型
     * List<Cinema>表示xml里面的resultMap => 表示返回的结果类型
     * queryCinemaByPage表示xml里面的id,类似xml中sql语句的索引,xml根据id来找到xml中对应的sql语句
     * 类似方法名,然后xml调用该方法
     */
    // 根据条件查询影院
    @GetMapping("/queryCinemaByCondition")
    public List<Cinema> queryCinemaByCondition(Cinema cinema) {
        return cinemaService.queryCinemaByCondition(cinema);
    }

    // 分页查询影院
    @GetMapping("/queryCinemaByPage")
    public TableDataInfo queryCinemaByPage(Cinema cinema) {
        startPage();
        List<Cinema> list = cinemaService.queryCinemaByPage(cinema);

        return getDataTable(list);
    }

    // 新增影院
    @PostMapping("/addCinema")
    public AjaxResult addCinema(@RequestBody Cinema cinema) {
        cinemaService.addCinema(cinema);
        return AjaxResult.success();
    }

    // 修改影院
    @PutMapping("/updateCinema")
    public AjaxResult updateCinema(@RequestBody Cinema cinema) {
        cinemaService.updateCinema(cinema);
        return AjaxResult.success();
    }

    // 删除影院
    @DeleteMapping("/deleteCinema/{cinemaIds}")
    public AjaxResult deleteCinema(@PathVariable String[] cinemaIds) {
        cinemaService.deleteCinemaByIds(cinemaIds);
        return AjaxResult.success();
    }
}
